package com.apes.scm.masterdata.product.repository;

import com.apes.framework.jpa.repository.CustomRepository;
import com.apes.scm.masterdata.product.model.Classify;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.Map;

/**
 * @author HuJianlin
 * @create 2018-03-15 11:04
 */
public interface ClassifyRepository extends CustomRepository<Classify, String> {

    @Query("SELECT T FROM Classify T WHERE T.id like %:value% or T.name like %:value%")
    Page<Classify> find(@Param("value") String value, Pageable pageable);

    @Query("select new map(T.id as id,T.name as name,T.parents.id as parentsId ,T.levels as levels,T.lastStage as lastStage,T.valid as valid) from Classify T order by T.id")
    List<Map> findTreeData();
}
